package cnpm02.j2ee.group3.ui.facalets;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.BooleanUtils;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

/**
 * The central place for handling the modal panel action.
 *
 * @author hun
 *
 */
@Name(ModalPanelAction.MODAL_PANEL_ACTION)
@Scope(ScopeType.CONVERSATION)
@AutoCreate
public class ModalPanelAction {
    public static final String MODAL_PANEL_ACTION = "modalPanelAction";
    private Map<String, Boolean> showedDialogsSet = new HashMap<String, Boolean>();
    
    @Begin(join=true)
    public boolean isShowed(String name) {
        return showedDialogsSet.containsKey(name);
    }
    
    /**
     * shows the dialog for edit mode.
     * @param name the dialog Id
     */
    @Begin(join=true)
    public void show(String name) {
        show(name, false);
    }

    /**
     * shows the dialog with the specified mode for new/edit.
     * @param name
     * @param isNewMode : true is new mode
     */
    @Begin(join=true)
    public void show(String name, boolean isNewMode) {
        showedDialogsSet.put(name, isNewMode);
    }
    
    public void hide(String name) {
        showedDialogsSet.remove(name);
    }
    
    public static ModalPanelAction getInstance() {
        return (ModalPanelAction) Component.getInstance(MODAL_PANEL_ACTION);
    }

    public boolean isNewMode(String dialogId) {
        if(showedDialogsSet.get(dialogId) == null) {
        	return false;
        } else {
        	return showedDialogsSet.get(dialogId);
        }
    }
}